home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Em / stream.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  5.5 KB  |  183 lines

  1. /*  C O P Y R I G H T   N O T I C E :                                     */
  2. /* Copyright 1986 Eric Jul and Norm Hutchinson.     May not be used for any  */
  3. /* purpose without written permission from the authors.              */
  4.  
  5. #ifdef xkernel
  6. #include "xstream.c"
  7. #else
  8.  
  9. #include <stdio.h>
  10. #include <sys/time.h>
  11. #include "Kernel/h/assert.h"
  12. #include "Kernel/h/emTypes.h"
  13. #include "Kernel/h/kmdTypes.h"
  14. #include "Kernel/h/builtins.h"
  15. #include "Kernel/h/emeraldTypes.h"
  16. #include "Kernel/h/mmMsgTypes.h"
  17. #include "Kernel/h/emkDefs.h"
  18.  
  19. extern ODP              OTLookup();
  20. extern AbConPtr         OIDOIDOIDToAbCon();
  21. extern OID              getNextOID();
  22. extern CompilerLoadReqPtr CReq[];
  23. extern ODP              KernelCheatingCreate();
  24.  
  25. CodePtr                 inStreamCodePtr, outStreamCodePtr;
  26. GODP                    kernelStdInStream, kernelStdOutStream;
  27. AbConPtr                inStreamAbCon, outStreamAbCon;
  28.  
  29. /**********************************************************************/
  30.  
  31. GODP MakeOutStream(fSock)
  32. int                     fSock;
  33. {
  34.     GODP                x;
  35.     AVariable           param[1];
  36.     param[0].myAbConPtr     = OIDOIDOIDToAbCon(
  37.     OIDOfBuiltin(B_INSTAT, INTEGERINDEX), (OID) NIL,
  38.     OIDOfBuiltin(B_INSTCT, INTEGERINDEX));
  39.     param[0].myAddr         = (DataAddr) fSock;
  40.     x = (GODP)
  41.       KernelCheatingCreate(getNextOID(), outStreamCodePtr->ownOID, 1, param);
  42.     return x;
  43. }
  44.  
  45. GODP MakeInStream(fSock)
  46. int                     fSock;
  47. {
  48.     GODP                x;
  49.     AVariable           param[1];
  50.     param[0].myAbConPtr     = OIDOIDOIDToAbCon(
  51.     OIDOfBuiltin(B_INSTAT, INTEGERINDEX), (OID) NIL,
  52.     OIDOfBuiltin(B_INSTCT, INTEGERINDEX));
  53.     param[0].myAddr         = (DataAddr) fSock;
  54.     x = (GODP)
  55.       KernelCheatingCreate(getNextOID(), inStreamCodePtr->ownOID, 1, param);
  56.     return x;
  57. }
  58.  
  59. void MakeStreamsFromSock(fSock, fInStreamPtr, fOutStreamPtr)
  60. int             fSock;
  61. GODP           *fInStreamPtr, *fOutStreamPtr;
  62. {
  63.     KMDTrace("UserIO", 3, "Making streams for sock #%d\n", fSock);
  64.     *fInStreamPtr = MakeInStream(fSock);
  65.     *fOutStreamPtr = MakeOutStream(fSock);
  66. }
  67.  
  68. /**********************************************************************/
  69.  
  70. /* Kernel call */
  71. void GetStdOut()
  72. {
  73.     currentSSP->resultBrand = VariableBrand;
  74.     currentSSP->regs.arg1 = (int) kernelStdOutStream;
  75.     currentSSP->regs.arg2 = (int) outStreamAbCon;
  76. }
  77.  
  78.  
  79. /* Kernel call */
  80. void GetStdIn()
  81. {
  82.     currentSSP->resultBrand = VariableBrand;
  83.     currentSSP->regs.arg1 = (int) kernelStdInStream;
  84.     currentSSP->regs.arg2 = (int) inStreamAbCon;
  85. }
  86.  
  87. /* Kernel call */
  88. void GetMyStdOut()
  89. {
  90.     register int                    i;
  91.     register CompilerLoadReqPtr     req;
  92.     
  93.     for (i = 0; i < 32; i++)
  94.     if ((CReq[i] != (CompilerLoadReqPtr) NULL)) {
  95.     req = CReq[i];
  96.     if (req->createdObj == currentSSP->regs.b) {
  97.         currentSSP->resultBrand = VariableBrand;
  98.         currentSSP->regs.arg1 = (int) req->theOutStream;
  99.         currentSSP->regs.arg2 = (int) outStreamAbCon;
  100.         return;
  101.     }
  102.     }
  103.     /* Not found, so return kernel stdout */
  104.     currentSSP->resultBrand = VariableBrand;
  105.     currentSSP->regs.arg1 = (int) kernelStdOutStream;
  106.     currentSSP->regs.arg2 = (int) outStreamAbCon;
  107.     
  108. }
  109. /* Kernel call */
  110. void GetMyStdIn()
  111. {
  112.     register int                    i;
  113.     register CompilerLoadReqPtr     req;
  114.     
  115.     for (i = 0; i < 32; i++)
  116.     if ((CReq[i] != (CompilerLoadReqPtr) NULL)) {
  117.     req = CReq[i];
  118.     if (req->createdObj == currentSSP->regs.b) {
  119.         currentSSP->resultBrand = VariableBrand;
  120.         currentSSP->regs.arg1 = (int) req->theInStream;
  121.         currentSSP->regs.arg2 = (int) inStreamAbCon;
  122.         return;
  123.     }
  124.     }
  125.  
  126.     currentSSP->resultBrand = VariableBrand;
  127.     currentSSP->regs.arg1 = (int) kernelStdInStream;
  128.     currentSSP->regs.arg2 = (int) inStreamAbCon;
  129. }
  130.  
  131. /**********************************************************************/
  132. /*      StreamInit                                                    */
  133. /**********************************************************************/
  134. void StreamInit()
  135. {
  136.     CodeODP                     outStreamCodeODP, inStreamCodeODP;
  137.     CompilerLoadReqPtr          req;
  138.  
  139.     KMDTrace("UserIO", 5, "StreamInit\n");
  140.  
  141.     outStreamCodeODP =
  142.     (CodeODP) OTLookup(OIDOfBuiltin(B_INSTCT,OUTSTREAMINDEX));
  143.     assert(NonNULL(outStreamCodeODP));
  144.     outStreamCodePtr    = outStreamCodeODP->dataPtr;
  145.     assert(NonNULL(outStreamCodePtr));
  146.  
  147.     inStreamCodeODP =
  148.     (CodeODP) OTLookup(OIDOfBuiltin(B_INSTCT,INSTREAMINDEX));
  149.     assert(NonNULL(inStreamCodeODP));
  150.     inStreamCodePtr    = inStreamCodeODP->dataPtr;
  151.     assert(NonNULL(inStreamCodePtr));
  152.  
  153.     kernelStdOutStream  = MakeOutStream(fileno(stdout));
  154.     /* Convention: InStreams that are created with sock -1 are closed when
  155.        created.  kernelStdInStream thus returns EOF on the first read
  156.        attempt */
  157.     kernelStdInStream   = MakeInStream(-1);
  158.  
  159.     outStreamAbCon      = OIDOIDOIDToAbCon(
  160.     OIDOfBuiltin(B_INSTAT,OUTSTREAMINDEX), (OID) NIL,
  161.     OIDOfBuiltin(B_INSTCT,OUTSTREAMINDEX));
  162.     inStreamAbCon       = OIDOIDOIDToAbCon(
  163.     OIDOfBuiltin(B_INSTAT,INSTREAMINDEX), (OID) NIL,
  164.     OIDOfBuiltin(B_INSTCT,INSTREAMINDEX));
  165.  
  166.     /* Create a request for kernel stdout */
  167.     req                 = mNewRequest(CompilerLoad);
  168.     req->status         = Translating;
  169.     req->sock           = fileno(stdout);
  170.     req->createdCTOID   = (OID) NULL;
  171.     req->createdObj     = (GODP) NULL;
  172.     req->theInStream    = (GODP) NULL;
  173.     req->theOutStream   = kernelStdOutStream;
  174.     req->waitingRead    =
  175.     req->waitingWrite   = (SSPtr) NULL;
  176.     req->vectorRead     =
  177.     req->vectorWrite    = (VectorPtr) NULL;
  178.     req->hangAround     = TRUE;
  179.     CReq[fileno(stdout)]= req;
  180. }
  181.  
  182. #endif xkernel
  183.